﻿using MediatR;
using W.Product.API.Appliaction.Command.ProductTypeCommand;
using W.Product.Repository.Interface;

namespace W.Product.API.Appliaction.CommandHandler.ProductTypeCommandHandler
{
    public class ProductTypeCreateCommandHandler : IRequestHandler<ProductTypeCreateCommand, int>
    {
        private readonly IProductTypeRepository  _repository;
        public ProductTypeCreateCommandHandler(IProductTypeRepository repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 创建产品类型
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(ProductTypeCreateCommand request, CancellationToken cancellationToken)
        {
            var list = await _repository.Add(new Domain.Product.ProductType()
            {
                ProductTypeNo = request.ProductTypeNo,
                ProductTypeName = request.ProductTypeName,
                ProductSuperior = request.ProductSuperior,
                ProductRemarks = request.ProductRemarks,
                officeId = "10086",
                userid=10010,
                IsDelete = false,
                CreateName="admin",
                CreateTime=DateTime.Now,

            });
            return list;
        }
    }
}
